package com.kaxicore.kaxi.httpResult;

import org.springframework.util.StringUtils;

/**
 * 响应结果生成工具
 */
public class ResultGenerator {

    /**
     * default SuccessResult
     */
    public static com.kaxicore.kaxi.httpResult.Result genSuccessResult() {
        return new com.kaxicore.kaxi.httpResult.Result();
    }

    /**
     * SuccessResult with data
     */
    public static <T> com.kaxicore.kaxi.httpResult.Result<T> genSuccessResult(T data) {
        return new com.kaxicore.kaxi.httpResult.Result(com.kaxicore.kaxi.httpResult.ResultCode.SUCCESS, data);
    }

    /**
     * default FailResult
     */
    public static com.kaxicore.kaxi.httpResult.Result genFailResult() {
        return new com.kaxicore.kaxi.httpResult.Result(com.kaxicore.kaxi.httpResult.ResultCode.FAIL.code, com.kaxicore.kaxi.httpResult.ResultCode.FAIL.message());
    }

    /**
     * FailResult with message
     */
    public static com.kaxicore.kaxi.httpResult.Result genFailResult(String message) {
        return new com.kaxicore.kaxi.httpResult.Result(com.kaxicore.kaxi.httpResult.ResultCode.FAIL.code, message);
    }

    public static com.kaxicore.kaxi.httpResult.Result genFailResult(com.kaxicore.kaxi.httpResult.ResultCode resultCode) {
        return new com.kaxicore.kaxi.httpResult.Result(resultCode.code, resultCode.message());
    }

    public static com.kaxicore.kaxi.httpResult.Result genFailResult(com.kaxicore.kaxi.httpResult.ResultCode resultCode, com.kaxicore.kaxi.httpResult.ResultSubResultCode subResultCode) {
        return new com.kaxicore.kaxi.httpResult.Result(resultCode, subResultCode);
    }

    public static com.kaxicore.kaxi.httpResult.Result genFailResult(com.kaxicore.kaxi.httpResult.ResultCode resultCode, String message) {
        return new com.kaxicore.kaxi.httpResult.Result(resultCode.code, message);
    }

    public static <T> com.kaxicore.kaxi.httpResult.Result<T> genFailResult(com.kaxicore.kaxi.httpResult.ResultCode resultCode, com.kaxicore.kaxi.httpResult.ResultSubResultCode subResultCode, T data) {
        return new com.kaxicore.kaxi.httpResult.Result(resultCode, subResultCode, data);
    }

    public static com.kaxicore.kaxi.httpResult.Result ok(Object data) {
        return new com.kaxicore.kaxi.httpResult.Result(com.kaxicore.kaxi.httpResult.ResultCode.SUCCESS, data);
    }

    public static com.kaxicore.kaxi.httpResult.Result ok() {
        return new com.kaxicore.kaxi.httpResult.Result();
    }

    public static com.kaxicore.kaxi.httpResult.Result error(String message) {
        return error(message, null);
    }

    public static Result error(String message, Object data) {
        return new Result(ResultCode.FAIL.code, StringUtils.isEmpty(message) ? ResultCode.API_PROCESSING_FAILED.message() : message, data);
    }
}
